<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">服务名称</label>
        <div class="layui-input-block">
            <input  name="title" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">医院</label>
        <div class="layui-input-block">
            <select name="hospitalId" lay-verify="required" id="hselect">
                <option value="">--请选择所属医院--</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">服务类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="全包" title="豪华全包" checked="">
            <input type="radio" name="type" value="分时" title="分时计费">
            <input type="radio" name="type" value="按次" title="一口价按次">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">封面图片</label>
        <div class="layui-input-block">
            <input name="imgurl" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">服务价格</label>
        <div class="layui-input-block">
            <input type="number" name="basePrice" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">服务特色</label>
        <div class="layui-input-block">
            <textarea name="feature" class="layui-textarea" placeholder="请输入"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">服务介绍</label>
        <div class="layui-input-block">
            <textarea name="info" class="layui-textarea" placeholder="请输入"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../lib/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //请求接口
            $.post("/api/serve/add",data.field,r=>{
                if(r.code==0){
                    layer.alert("新增医院陪诊服务成功！");
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    //刷新列表页面数据
                    window.parent.location.reload();
                }else {
                    layer.alert(r.data)
                }
            })

            return false;
        });

        //加载请求 获取医院列表 进行下拉框渲染
        $.get("/api/hospital/all",r=>{
            // 动态生成下拉框选项
            var selectHtml = '';
            for(var i = 0; i < r.data.length; i++){
                selectHtml += '<option value="' + r.data[i].id + '">' + r.data[i].name + '</option>';
            }
            document.getElementById('hselect').innerHTML = selectHtml;
            //渲染
            form.render('select'); //刷新select选择框渲染
        })
    });
</script>
</body>
</html>